package com.qfmy.controller.novel;

import com.qfmy.service.novel.NovelService;
import com.qfmy.vo.novel.NovelVo;
import common.result.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.controller.novel
 * @date 2025/6/6
 * @description 小说控制类
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/novel")
public class NovelController {

    /**
     * 注入service
     */
    @Resource
    private NovelService novelService;

    /**
     * 获取热门标签小说
     */
    @RequestMapping("/getHotNovels")
    public Result<List<NovelVo>> getHotNovels() {
        List<NovelVo> hotNovels = novelService.getHotNovels();
        return Result.ok(hotNovels);
    }

    /**
     * 感觉不同的类型获取热门数据
     */
    @RequestMapping("/getHotNovelsByType")
    public Result<List<NovelVo>> getHotNovelsByType(@RequestParam String name) {
        List<NovelVo> hotNovels = novelService.getHotNovelsByType(name);
        return Result.ok(hotNovels);
    }

    /**
     * 获取排行榜数据
     */
    @RequestMapping("/getRankNovels")
    public Result<List<NovelVo>> getRankNovels() {
        List<NovelVo> rankNovels = novelService.getRankNovels();
        return Result.ok(rankNovels);
    }

    /**
     * 获取限时间免费
     */
    @RequestMapping("/getFreeNovels")
    public Result<List<NovelVo>> getFreeNovels() {
        List<NovelVo> freeNovels = novelService.getFreeNovels();
        return Result.ok(freeNovels);
    }
    /**
     * 获取用户喜爱的小说
     */
    @RequestMapping("/getUserLikeNovels")
    public Result<List<NovelVo>> getUserLikeNovels(@RequestParam Integer pageNum, @RequestParam Integer size) {
        List<NovelVo>  userLikeNovels = novelService.getUserLikeNovels(pageNum,size);
        return Result.ok(userLikeNovels);
    }

    /**
     * 获取最新发布的小说
     */
    @RequestMapping("/getNewestNovels")
    public Result<List<NovelVo>> getNewestNovels() {
        List<NovelVo> newestNovels = novelService.getNewestNovels();
        return Result.ok(newestNovels);
    }

    /**
     * 分页获取排行榜数据
     */
    @RequestMapping("/getRankNovelsByPage")
    public Result<List<NovelVo>> getRankNovelsByPage(@RequestParam String tag, @RequestParam Integer pageNum, @RequestParam Integer size)
    {
        List<NovelVo> rankNovels = novelService.getRankNovelsByPage(tag,pageNum,size);
        return Result.ok(rankNovels);
    }

    /**
     * 根据小说的类型分页获取小说
     */
    @RequestMapping("/getNovelsByType")
    public Result<List<NovelVo>> getNovelsByType(@RequestParam String type, @RequestParam Integer pageNum, @RequestParam Integer size,@RequestParam Integer sort)
    {
        List<NovelVo> rankNovels = novelService.getNovelsByType(type,pageNum,size, sort);
        return Result.ok(rankNovels);
    }

    /**
     * 获取评分最高的最新的小说
     */
    @RequestMapping("/getNewRankNovels")
    public Result<List<NovelVo>> getNewNovels()
    {
        List<NovelVo> rankNovels = novelService.getNewRankNovels();
        return Result.ok(rankNovels);
    }

    /**
     * 获取潜力新书
     */
    @RequestMapping("/getPotentialNewBook")
    public Result<List<NovelVo>> getPotentialNewBook()
    {
        List<NovelVo> potentialNewBook = novelService.getPotentialNewBook();
        return Result.ok(potentialNewBook);
    }

    /**
     * 获取新书首发
     */
    @RequestMapping("/getNewBookReleases")
    public Result<List<NovelVo>> getNewBookReleases()
    {
        List<NovelVo> newestNovels = novelService.getNewBookReleases();
        return Result.ok(newestNovels);
    }

    /**
     * 搜索小说
     */
    @RequestMapping("/searchBook")
    public Result<List<NovelVo>> searchBook(@RequestParam String keyword)
    {
        List<NovelVo> searchBooks = novelService.searchBook(keyword);
        return Result.ok(searchBooks);
    }

    /**
     * 获取热收索数据
     */
    @RequestMapping("/getHotSearch")
    public Result<List<NovelVo>> getHotSearch(@RequestParam Integer pageNum,@RequestParam Integer size)
    {
        List<NovelVo> hotSearch = novelService.getHotSearch(pageNum,size);
        return Result.ok(hotSearch);
    }

    /**
     * 更新搜索次数
     */
    @RequestMapping("/updateSearch")
    public  Result<String> updateSearch(@RequestParam Long novelId)
    {
        novelService.updateSearch(novelId);
        return Result.ok("更新成功");
    }

    /**
     * 更新阅读次数
     */
    @RequestMapping("/updateViewCount")
    public  Result<String> updateViewCount(@RequestParam Long novelId)
    {
        novelService.updateViewCount(novelId);
        return Result.ok("更新成功");
    }

    /**
     * 根据小说id获取小说
     */
    @RequestMapping("/getNovelById")
    public Result<NovelVo> getNovelById(@RequestParam Long novelId) {
        NovelVo novelVo = novelService.getNovelById(novelId);
        return Result.ok(novelVo);
    }


}
